﻿using System;
using System.Web.Configuration;
using System.Data;

public partial class product_Mask_medical_Default : System.Web.UI.Page
{
    DBHelper db = new DBHelper(WebConfigurationManager.ConnectionStrings["connString"].ConnectionString);
    public int renum = 0;
    public string HtmlStr = "";
    public string PageHtmlStr = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        GetRole("4");
        GetProductHtml();
        GetPageHtml();
    }

    public void GetRole(string pbid)
    {
        string roleid = Session[AppConfig.SESSION_USER_ROLE_ID].ToString();

        if (roleid.Contains(pbid))
        {

        }
        else
        {
            Response.Redirect("/build/role.html");
        }

    }

    public void GetProductHtml()
    {
        string sql = "select  * from Production where typeID=4 and IsUsing=1";
        DataTable dt = db.getList(sql);
        renum = dt.Rows.Count;
        int j = 1;
        int i = 0;
        HtmlStr = "<div id =\"html_page_" + j + "\" class=\"main-content-center\">";
        HtmlStr += "<div class=\"mask-variety\">";

        foreach (DataRow dr in dt.Rows)
        {
            string imgfile = "/static/img/zzz.jpg";
            if (dr["imgfile"].ToString() != "" && dr["imgfile"].ToString() != "null" && dr["imgfile"].ToString() != "NULL")
            {
                imgfile = "http://logocatalogue.sanqicn.com/upload/image/product/img/" + dr["imgfile"].ToString();
            }

            if (i % 12 == 0 & i != 0)
            {
                j++;
                HtmlStr += "</div>";
                HtmlStr += "</div>";
                HtmlStr += "<div id =\"html_page_" + j + "\" class=\"main-content-center\" style=\"display:none\">";
                HtmlStr += "<div class=\"mask-variety\">";
                HtmlStr += "<div class=\"mask-variety-img\">";
                HtmlStr += "<a target=\"_blank\" href=\"View.aspx?id=" + dr["id"].ToString() + "\" class=\"children-mask1\" style=\"background: white url('" + imgfile + "') center no-repeat; background-size: contain;\"></a>";
                HtmlStr += "<span>" + dr["name"].ToString() + "</span>";
                HtmlStr += "</div>";
            }
            else
            {
                if (i % 4 == 0 & i != 0)
                {
                    HtmlStr += "</div>";
                    HtmlStr += "<div class=\"mask-variety\">";
                    HtmlStr += "<div class=\"mask-variety-img\">";
                    HtmlStr += "<a target=\"_blank\"  href=\"View.aspx?id=" + dr["id"].ToString() + "\" class=\"children-mask1\" style=\"background: white url('" + imgfile + "') center no-repeat; background-size: contain;\"></a>";
                    HtmlStr += "<span>" + dr["name"].ToString() + "</span>";
                    HtmlStr += "</div>";
                }
                else
                {
                    HtmlStr += "<div class=\"mask-variety-img\">";
                    HtmlStr += "<a target=\"_blank\"  href=\"View.aspx?id=" + dr["id"].ToString() + "\" class=\"children-mask1\" style=\"background: white url('" + imgfile + "') center no-repeat; background-size: contain;\"></a>";
                    HtmlStr += "<span>" + dr["name"].ToString() + "</span>";
                    HtmlStr += "</div>";
                }
            }
            if (i == dt.Rows.Count - 1)
            {
                HtmlStr += "</div></div>";
            }
            i++;
        }
    }

    public void GetPageHtml()
    {
        ReNum.Value = renum.ToString();
        string midhtml = "";
        int pagenum = renum / 12;
        if (renum % 12 > 0) pagenum = pagenum + 1;
        PageNum.Value = pagenum.ToString();
        PageHtmlStr += "<input type=\"button\" value=\"首页\" onclick=\"SetPage('first', 0)\"/>";
        PageHtmlStr += "&nbsp;<input type=\"button\" value=\"上一页\" onclick=\"SetPage('previous', 0)\"/>";
        for (int i = 1; i <= pagenum; i++)
        {
            midhtml += "&nbsp;<a  style=\"cursor: pointer\" id=\"nowpage_" + i + "\" onclick=\"SetPage('jump'," + i + ")\">" + i + "</a>";
        }
        PageHtmlStr += midhtml;
        PageHtmlStr += "&nbsp;<input type=\"button\" value=\"下一页\" onclick=\"SetPage('next', 0)\" />";
        PageHtmlStr += "&nbsp;<input type=\"button\" value=\"尾页\" onclick=\"SetPage('last', 0)\" />";
        PageHtmlStr += "&nbsp;<a>共<span id=\"totalPage\">" + pagenum + "</span>页/<span id=\"totalNumbers\">" + renum + "</span>条数据</a>";
    }


}
